package models;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * 多图文信息模型
 * 
 * @author ultrafrog
 * @version 1.0, 2014-12-10
 * @since 1.0
 */
@Entity
@Table(name = "uwx_article_multi")
public class ArticleMulti extends Model {

	/** 副图文信息 */
	@Column(name = "vc_articles")
	public String articleIds;
	
	/** 时间 */
	@Column(name = "dt_datetime")
	public Date datetime;
	
	/** 图文信息列表 */
	@Transient
	private List<Article> articles;
	
	/** 构造函数 */
	public ArticleMulti() {
		datetime = new Date();
	}
	
	/**
	 * 读取图文信息列表
	 * 
	 * @return
	 */
	public List<Article> getArticles() {
		if (articles == null) {
			articles = new ArrayList<Article>();
			for (String id: articleIds.split(",")) {
				articles.add(Article.class.cast(Article.findById(id)));
			}
		}
		return articles;
	}
}
